package com.plugin.core.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyStringUtil {

    private static Logger log= LoggerFactory.getLogger(MyStringUtil.class);

    public static boolean equalsIgnoreCase(String src,String dest) {
        boolean b=false;
        if (src != null && dest != null) {
            if(src.equalsIgnoreCase(dest.toLowerCase())){
                b=true;
            }else{
                b=false;
            }
        }
        return b;
    }

    public static boolean isNotBlank(String target) {
        if("".equals(target)||null==target){
            return false;
        }
        return true;
    }


    public static boolean isBlank(String target) {
        if(target==null||"".equals(target)){
            return true;
        }
        return false;
    }


    public static <T extends Object> Object overrideIsNull(T t){

        if(t instanceof String){
            if (t == null) {
                return "";
            }
        }else if(t instanceof Integer){
            if (t == null) {
                return 0;
            }
        }else if(t instanceof Long){
            if (t == null) {
                return 0L;
            }
        }
        return t;
    }

    /**
     *
     * @param //原始字符串
     * @param s //要替换的字符
     * @param a  //开始长度的下标
     * @param b  //结束长度的下表
     */
    public static String replaceAnyChars(String origin,char s,int a,int b){
        StringBuffer sb = new StringBuffer();
        char ch[] = origin.toCharArray();

        for(int i=0;i<ch.length;i++){
            if(a>=0&&b<ch.length&&a<b){
                if(a<=i&&i<=b){
                    sb.append(s);
                }else {
                    sb.append(ch[i]);
                }
            }else {
                log.error("不符合替换规则......");
            }
        }

        return sb.toString();
    }
}
